home *** CD-ROM | disk | FTP | other *** search
- Path: news.compuserve.com!newsmaster
- From: uszvnwgn@ibmmail.com (Harold Putman)
- Newsgroups: comp.lang.c
- Subject: Re: PLEASE PLEASE HELP HELP...question on interleaving C functions
- Date: Thu, 11 Jan 1996 00:45:43 GMT
- Organization: CompuServe Incorporated
- Message-ID: <4d1c1r$rqa@dub-news-svc-2.compuserve.com>
- References: <1995Dec30.194449.16565@wvnvms>
- NNTP-Posting-Host: ad52-024.compuserve.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- un025043@wvnvms.wvnet.edu wrote:
-
- >The scenario...
-
- >main()
- >{
-
- >sub1(parameters);
- >sub2(parameters);
-
- >}
-
- >sub1(...)
- >{
- >..some statemenmts
- >}
-
- >sub2(...)
- >{
- >..some statements
- >}
-
- >I intend main to call sub1, such that sub1 executes ONLY 1 INSTRUCTION, &
- >returns control to main.
- >Main then calls sub2, which again executes a single instrcution & returns.
- >Main then calls sub1, which executes the next instruction ( only 1 again)
- >and returns to main.
- >Main thus calls sub1, sub2, sub1, sub2 alternately until both sub1 & sub2
- >run out of instructions.
-
- try something like this
-
- #define DONE 1
- #define NOT_DONE 0
- int sub1()
- {
- static int instruction = 1;
- switch(instruction)
- {
- case 1:
- [first instruction];
- break;
- case 2:
- [second instruction];
- break;
- ...
- deafult:
- return DONE;
- }
- instruction++;
- return NOT_DONE;
- }
-
- Sub2 would look just like sub1 but with different instructions. Your
- main could look like...
-
- main()
- {
- do
- {
- done1 = sub1();
- done2 = sub2();
- } while(!done1 && !done2);
- }
-
- This ought to do the trick for you, but document carefully that the
- cases in sub1 and sub2 are always executed in order starting with case
- 1. I actually used something like this once. It does the job but it is
- sort a maintenance headache since it is not immediatley obvious what
- is going on.
-
- Harold Putman
- InterBold Dept. 9-52 / IBMMAIL: USZVNWGN
- 5995 Mayfair Rd. / Internet: uszvnwgn@ibmmail.com
- North Canton, OH 44720 / CompuServe: 73744,2632
- USA / Tel: (216) 490-4723 FAX: (216) 490-4508
-
-
-
-